package com.example.sys.module.service.impl;

import com.example.sys.module.mode.SysModuleInfo;
import com.example.sys.module.service.SysModuleRoleService;
import com.example.utils.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class SysModuleAddRoleServiceImpl implements SysModuleRoleService {
    @Value("${add.roleAlias}")
    private String roleAlias;

    @Override
    public void loadRoleMap(Map<String, String> map, SysModuleInfo sysModuleInfo) {
        String baseRole = sysModuleInfo.getBaseRole();
        String key = PREF + StringUtils.toLowerCaseFirstOne(sysModuleInfo.getEntityClass().getSimpleName()) + ADD_AUTH;
        String val = ROLE_PREF + baseRole + BLANK + baseRole + ADD + ROLE_END;
        map.put(key, val);
    }

    @Override
    public Map<String, String> getRoleMap(SysModuleInfo sysModuleInfo) {
        Map<String, String> map = new HashMap<>();
        map.put(sysModuleInfo.getBaseRole() + ADD, this.roleAlias);
        return map;
    }
}
